<%@ page language="java" contentType="text/html;charset=utf-8" pageEncoding="utf-8" %>

<%@ page import="com.sms.day_report.*" %>
<%@ page import="java.util.List, java.util.ArrayList, java.util.Map" %>

<%--
	project/teacher/report-detail.jsp
 --%>

<%	//清除内存
	response.setHeader("Pragma","No-cache"); 
	response.setHeader("Cache-Control","no-cache"); 
	response.setDateHeader("Expires", 0); 
%>

<%
	request.setCharacterEncoding("utf-8");
	String userno = (String)session.getAttribute("userno");
	
	//String url =request.getRequestURL() + (request.getQueryString() == null? "" : "?") + request.getQueryString();	
	//得到该项目的对象并赋值
	List<Day_report> list = new ArrayList<Day_report>();	

	List<Day_report> prlist1 = Day_report.getPReport( userno);
	List<Day_report> oprlist1 = Day_report.getOtherPReport(userno);
	
	int myTotalRecords = 0;
	int otherTotalRecords = 0;
	int totalRecords = 0;
	int totalPage = 0;
	int pageSize = 10;//设置每页显示条数
	if(prlist1 != null && prlist1.size() > 0) {
		myTotalRecords = prlist1.size();
	}
	if(oprlist1 != null && oprlist1.size() > 0) {
		otherTotalRecords = oprlist1.size();
	}
	totalRecords = myTotalRecords +  otherTotalRecords;
	totalPage = (totalRecords + pageSize -1)/pageSize;
	
	if(totalPage < 1) {
		totalPage = 1;
	}
	int pageNo = 1;
	try {
		pageNo = Integer.parseInt(request.getParameter("pageNo"));
		if(pageNo < 1) {
			pageNo = 1;
		} else if(pageNo > totalPage) {
			pageNo = totalPage;
		}
	} catch(NumberFormatException e) {
		pageNo = 1;
	}
	int startPos = (pageNo -1)*pageSize;
	
	List<Day_report> prlist = new ArrayList<Day_report>();;
	List<Day_report> oprlist = new ArrayList<Day_report>();;
	if(startPos <= myTotalRecords) {
		if(myTotalRecords >= (pageNo * pageSize)) {
			prlist = Day_report.getPReport(userno, startPos, pageSize);;
		} else {
			int n = myTotalRecords - startPos;//展示条数
			prlist = Day_report.getPReport( userno, startPos, n);
			int  i=1;
			oprlist = Day_report.getOtherPReport(userno, i-1, pageSize - n);
		}
	} else {
		oprlist = Day_report.getOtherPReport(userno, startPos - myTotalRecords, pageSize);
	}
%>	

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>

<div class="report-detail" style="overflow:auto;padding:10px  " >
  <br />
    <p style="text-align:center;" id='page'>第<%= pageNo %>页
    <% 
    	if(pageNo != 1) {
    %>
    <a href="javascript:void(0)" onclick="jump(<%= pageNo -1 %>);">上一页</a>
    <%}%>
    <% 
    	if(totalPage == 0) {
    		totalPage = 1;
    	}
    %>
   	<%
   		if(pageNo != totalPage) { 
   	%>
    		<a href="javascript:void(0)" onclick="jump(<%= pageNo + 1 %>);">下一页</a> 
    <% } %>
    	&nbsp;&nbsp;&nbsp;
    	共<%= totalPage %>页&nbsp;&nbsp;&nbsp;<a class="easyui-linkbutton" iconCls="icon-add" id="add">添加汇报</a></p>
<% 	//展示收到的汇报
int number = 0;
if(prlist != null && prlist.size() > 0) {
%>
<br/>
给我的汇报：
<%
	for(int i=0; i<prlist.size(); i++) {
		Day_report pr = prlist.get(i);
		number++;
%>
    <div style="overflow:auto;" title="From：<%= pr.getFromName() %>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  to:<%= pr.getToName() %>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Time：<%= pr.getP_reportTime() %>" id="<%= pr.getP_reportId() %>">
       <p class="content"><span class="people">From：<%= pr.getFromName() %>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  to:<%= pr.getToName() %>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Time：<%= pr.getP_reportTime() %><br />
      </span><br/>
     	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%= pr.getContent() %><br/><br/>
     	
      	</span>
      		<span style="text-align:right; display:block;">
      		&nbsp;&nbsp;&nbsp;楼主
    	 		<a id="reply" href="javascript:void(0)" onclick="show(<%= number %>);">回复</a>&nbsp;&nbsp;&nbsp;
    	 		<a id="packup" href="javascript:void(0)" onclick="disappear(<%= number %>);" >收起回复</a>&nbsp;&nbsp;&nbsp;
    	 			<a class="deleteroot" href="javascript:void(0)" onclick="dodel(<%= pr.getP_reportId() %>);">删除</a>&nbsp;&nbsp;&nbsp;
    	 		<form id="rep-content<%= number %>" onsubmit="return false;" style="display:none;margin-left: 250px;">
    	 			<input type="hidden" name="type" id="type" value="<%= pr.getType() %>" />
	    			<input type="hidden" name="rootid" id="rootid" value="<%= pr.getRootid()%>" />
	    			<input type="hidden" name="pid" id="pid" value="<%= pr.getP_reportId() %>" />
	    			<input type="hidden" name="fromid" id="fromid" value="<%= userno %>" />
	    			<input type="hidden" name="toid" id="toid" value="<%= pr.getFromId() %>" />
	    			<input type="text" id="replyTo" name="replyTO" value="TO:<%= pr.getFromName() %>"/><br/>
	    			<textarea id="content<%= number %>" name="content" style="width:50%;height:80px;overflow:scroll;"></textarea><br />
	    			<input type="submit" name="button" value="提交内容" onclick="dealReply(<%= number %>)" />
    			</form>
    	 	</span>
    </p>
    <% 
    	if(pr.getIsleaf().equals("1")) {//有回复（即非叶子节点）
    		List<Day_report> prrlist = new ArrayList<Day_report>();
    		prrlist.addAll(Day_report.getReplyReport(pr, 0));
    		if(prrlist != null && prrlist.size() >0) {
    			int n = 0;
    			for(int j=0; j<prrlist.size(); j++) {
    				Day_report prr = prrlist.get(j);
    				number++;
 
			    	String classes = "";
			    	String floor = "";
			    	if(prr.getGrade() > 1) {
			    		classes = "Reply2";
			    	} else {
			    		classes= "Reply";
			    		n ++;
			    		floor = n + "楼";
			    	}
    %>
    	<p class="<%= classes %>"><span class="people">From：<%= prr.getFromName() %>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  to:<%= prr.getToName() %>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Time：<%= prr.getP_reportTime()%><br />
      </span><br/>
     	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%= prr.getContent() %>
       	 	<span style="text-align:right; display:block;">
       	 		&nbsp;&nbsp;&nbsp;<%= floor %>
    	 		<a id="reply" href="javascript:void(0)" onclick="show(<%= number %>);">回复</a>&nbsp;&nbsp;&nbsp;
    	 		<a id="packup" href="javascript:void(0)" onclick="disappear(<%= number %>);" >收起回复</a>&nbsp;&nbsp;&nbsp;
    	 		<a class="deleteroot" href="javascript:void(0)" onclick="dodel(<%= prr.getP_reportId() %>);">删除</a>&nbsp;&nbsp;&nbsp;
    	 	</span>
	    	<form id="rep-content<%= number %>" onsubmit="return false;" style="display:none;margin-left: 250px;">
    			<input type="hidden" name="type" id="type" value="<%= prr.getType() %>" />
    			<input type="hidden" name="rootid" id="rootid" value="<%= prr.getRootid()%>" />
    			<input type="hidden" name="pid" id="pid" value="<%= prr.getP_reportId() %>" />
    			<input type="hidden" name="fromid" id="fromid" value="<%= userno %>" />
    			<input type="hidden" name="toid" id="toid" value="<%= prr.getFromId() %>" />
    			<input type="text" id="replyTo" name="replyTO" value="TO:<%= prr.getFromName() %>"/><br/>
    			<textarea id="content<%= number %>" name="content" style="width:50%;height:80px;overflow:scroll;"></textarea><br />
    			<input type="submit" name="button" value="提交内容" onclick="dealReply(<%= number  %>)" /> 
    		</form>
    	 
   		 </p>  
    <%
    			}
    		}
    	}
    %>
    </div>
<%
	}
	}
%>

<br/><br/>
<% 	//展示其他人的汇报
if(oprlist != null && oprlist.size() > 0) {
%>
其他人的汇报：
<%
	for(int i=0; i<oprlist.size(); i++) {
		Day_report pr = oprlist.get(i);
		number++;
%>
    <div style="overflow:auto;"  title="From：<%= pr.getFromName() %>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  to:<%= pr.getToName() %>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Time：<%= pr.getP_reportTime() %>" id="<%= pr.getP_reportId() %>">
       <p class="content"><span class="people">From：<%= pr.getFromName() %>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  to:<%= pr.getToName() %>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Time：<%= pr.getP_reportTime() %><br />
      </span><br/>
     	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%= pr.getContent() %><br/><br/>
     	
      	</span>
      		<span style="text-align:right; display:block;">
      		&nbsp;&nbsp;&nbsp;楼主
    	 		<a id="reply" href="javascript:void(0)" onclick="show(<%= number %>);">回复</a>&nbsp;&nbsp;&nbsp;
    	 		<a id="packup" href="javascript:void(0)" onclick="disappear(<%= number %>);" >收起回复</a>
    	 		<form id="rep-content<%= number %>" onsubmit="return false;" style="display:none;margin-left: 250px;">
    	 			<input type="hidden" name="type" id="type" value="<%= pr.getType() %>" />
	    			<input type="hidden" name="rootid" id="rootid" value="<%= pr.getRootid()%>" />
	    			<input type="hidden" name="pid" id="pid" value="<%= pr.getP_reportId() %>" />
	    			<input type="hidden" name="fromid" id="fromid" value="<%= userno %>" />
	    			<input type="hidden" name="toid" id="toid" value="<%= pr.getFromId() %>" />
	    			<input type="text" id="replyTo" name="replyTO" value="TO:<%= pr.getFromName() %>"/><br/>
	    			<textarea id="content<%= number %>" name="content" style="width:50%;height:80px;overflow:scroll;"></textarea><br />
	    			<input type="submit" name="button" value="提交内容" onclick="dealReply(<%= number %>)" />
    			</form>
    	 	</span>
    </p>
    <% 
    	if(pr.getIsleaf().equals("1")) {//有回复（即非叶子节点）
    		List<Day_report> prrlist = new ArrayList<Day_report>();
    		prrlist.addAll(Day_report.getReplyReport(pr, 0));
    		if(prrlist != null && prrlist.size() >0) {
    			int n = 0;
    			for(int j=0; j<prrlist.size(); j++) {
    				Day_report prr = prrlist.get(j);
    				number++;
 
			    	String classes = "";
			    	String floor = "";
			    	if(prr.getGrade() > 1) {
			    		classes = "Reply2";
			    	} else {
			    		classes= "Reply";
			    		n ++;
			    		floor = n + "楼";
			    	}
    %>
    	<p class="<%= classes %>"><span class="people">From：<%= prr.getFromName() %>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  to:<%= prr.getToName() %>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Time：<%= pr.getP_reportTime()  %><br />
      </span><br/>
     	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%= prr.getContent() %>
       	 	<span style="text-align:right; display:block;">
       	 		&nbsp;&nbsp;&nbsp;<%= floor %>
    	 		<a id="reply" href="javascript:void(0)" onclick="show(<%= number %>);">回复</a>&nbsp;&nbsp;&nbsp;
    	 		<a id="packup" href="javascript:void(0)" onclick="disappear(<%= number %>);" >收起回复</a>
    	 	</span>
	    	<form id="rep-content<%= number %>" onsubmit="return false;" style="display:none;margin-left: 250px;" >
    			<input type="hidden" name="type" id="type" value="<%= prr.getType() %>" />
    			<input type="hidden" name="rootid" id="rootid" value="<%= prr.getRootid()%>" />
    			<input type="hidden" name="pid" id="pid" value="<%= prr.getP_reportId() %>" />
    			<input type="hidden" name="fromid" id="fromid" value="<%= userno %>" />
    			<input type="hidden" name="toid" id="toid" value="<%= prr.getFromId() %>" />
    			<input type="text" id="replyTo" name="replyTO" value="TO:<%= prr.getFromName() %>"/><br/>
    			<textarea id="content<%= number %>" name="content" style="width:50%;height:80px;overflow:scroll;"></textarea><br />
    			<input type="submit" name="button" value="提交内容" onclick="dealReply(<%= number  %>)" /> 
    			&nbsp;&nbsp;
    		</form>
    	 
   		 </p>  
    <%
    			}
    		}
    	} 
    %>
    </div>
<%
	}
	}
%>
</div>
<div id="tt"></div>
<script type="text/javascript">
var num;
$('.report-detail').accordion({
	fit:true
	})
function show(i) {
	var content = "#rep-content" + i;
	$(content).appendTo($(this).parents("p")).end().css('display','block');
}

function disappear(i) {
	var content = "#rep-content" + i;
	$(content).appendTo($(this).parents("p")).end().css('display','none');
}


function deleteroot(i){
//alert(i);
$.post("day_report/delete_report.jsp",{'p_reportid':i},function(data){
 alert(data);
   var tab = $(".easyui-tabs").tabs('getSelected');;
			 		$(".easyui-tabs").tabs('update',
			                        {tab:tab,
									options:{
								       cache:false,
                                        href:'day_report/student/day_report.jsp'}
									}
									); 

});
}


function dodel(i) {
        if (confirm("确认要删除？")) {
        deleteroot(i);
        }
        else{
        window.event.returnValue = false;
        }
    }

function dealReply(i) {
	var contentNum = "#content" + i;
	var cont = $(contentNum).attr('value');
	if (cont) {
		var content = "#rep-content" + i;
		$.ajax({
		url:'day_report/student/reply.jsp',//添加链接，添加回复内容
		data:$(content).serialize(),
		dataType:'text',
		success:function(msg){
		if(msg=='ok'){
					var tab = $(".easyui-tabs").tabs('getSelected');
			 		$(".easyui-tabs").tabs('update',
			                        {tab:tab,
									options:{
								       cache:false,
                                        href:'day_report/student/day_report.jsp'}
									}
									); 
			alert('回复成功');
			/* $('#dd').dialog('refresh','project/teacher/report-detail.jsp?row=' + $('#row').attr('value') + '&progress=' + $('#progress').attr('value')); //刷新对话框,回复内容显示出来，回复输入框隐藏显示
			 $(content).appendTo($(this).parents("p")).end().css('display','none');
    		*/
    		}
			else{alert('回复失败，请重试');}
		}
		})
	} 
	else {
		alert('请补充完整信息');
		return false;
	}
			
}

function jump(i) {
//alert('hello');
//url = 'day_report/student/day_report.jsp?&pageNo=' + i;
//alert(url);	
	//$('#dd').dialog('refresh','day_report/student/day_report.jsp?&pageNo=' + i);

			var tab = $(".easyui-tabs").tabs('getSelected');;
			 		$(".easyui-tabs").tabs('update',
			                        {tab:tab,
									options:{
								       cache:false,
                                       href:'day_report/student/day_report.jsp?&pageNo=' + i}
									}
									);  /*更新面板*/

			
}


//添加汇报
$('#add').click(function(){
	 $('#tt').dialog({
		         title:"添加汇报",
				 zIndex:9001,
				 width:700, height:500,
				 top:50,left:300,
				 maximizable:true,
				 cache:false,
				 resizable:true,
				href:'day_report/student/add_presonreport.jsp' //记得加上相应的参数，标示汇报是哪一个项目的汇报
	})
	})
</script>
</body>
</html>
